{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>竞猜答题{:lang('list')}</legend>
    </fieldset>
    <div class="demoTable">
        <a href="{:url('index')}" class="layui-btn"  ><i class="fa fa-plus" aria-hidden="true"></i>返回</a>
        <a href="{:url('askadd')}?match_id={$match_id}" class="layui-btn" ><i class="fa fa-plus" aria-hidden="true"></i>{:lang('add')}</a>
        <button type="button" class="layui-btn layui-btn-danger" id="delAll">批量删除</button>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
<script type="text/html" id="is_lock">
    <input type="checkbox" name="is_lock" value="{{d.match_id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="is_lock" {{ d.is_lock == 0 ? 'checked' : '' }}>
</script>
<script type="text/html" id="order">
    <input name="ask_sort" data-id="{{d.ask_id}}" class="list_order layui-input" value=" {{d.ask_sort}}" size="10"/>
</script>
<script type="text/html" id="action">
    <a href="{:url('askedit')}?ask_id={{d.ask_id}}" class="layui-btn layui-btn-xs">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="email">
    {{d.email}}
    {{# if(d.email && d.email_validated=='0'){ }}
    (未验证)
    {{# } }}
</script>
<script type="text/html" id="ask_content">
    {{d.ask_content}}
</script>
{include file="common/foot"/}
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table, form = layui.form, $ = layui.jquery;
        var tableIn = table.render({
            id: 'match',
            elem: '#list',
            url: '{:url("matchask")}?match_id={$match_id}',
            method: 'post',
            page: true,
            cols: [[
                    {checkbox: true, fixed: true},
                    {field: 'ask_id', title: '{:lang("id")}', width: 80, fixed: true},
                    {field: 'ask_title', title: '标题', width: 150},
                    {field: 'ask_content', title: '内容', width: 350,templet: '#ask_content' },
                    {field: 'ask_result', title: '答案', width: 150, },
                    {field: 'ask_point', align: 'center', title: '积分', width: 150},

                    {width: 160, align: 'center', toolbar: '#action'}
                ]],
            limit: 50 //每页默认显示的数量
        });
        form.on('switch(is_lock)', function (obj) {
            loading = layer.load(1, {shade: [0.1, '#fff']});
            var id = this.value;
            var is_lock = obj.elem.checked === true ? 0 : 1;
            $.post('{:url("usersState")}', {'id': id, 'is_lock': is_lock}, function (res) {
                layer.close(loading);
                if (res.status == 1) {
                    tableIn.reload();
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                    return false;
                }
            })
        });
         $('body').on('blur','.list_order',function() {
            var id = $(this).attr('data-id');
            var ask_sort = $(this).val();
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post('{:url("listorder")}',{ask_id:ask_id,ask_sort:ask_sort},function(res){
                layer.close(loading);
                if(res.code === 1){
                    layer.msg(res.msg, {time: 1000, icon: 1}, function () {
                        location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            })
        });
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            if ($.trim(key) === '') {
                layer.msg('{:lang("pleaseEnter")}关键字！', {icon: 0});
                return;
            }
            tableIn.reload({
                where: {key: key}
            });
        });
        table.on('tool(list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除竞彩吗？', function (index) {
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}", {id: data.ask_id}, function (res) {
                        layer.close(loading);
                        if (res.code === 1) {
                            layer.msg(res.msg, {time: 1000, icon: 1});
                            tableIn.reload();
                        } else {
                            layer.msg('操作失败！', {time: 1000, icon: 2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

        $('#delAll').click(function () {
            layer.confirm('确认要删除选中信息吗？', {icon: 3}, function (index) {
                layer.close(index);
                var checkStatus = table.checkStatus('match'); //test即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.ask_id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('delall')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })

        //批量今日答案
        $('#todayAll').click(function () {
            layer.confirm('确认要批量今日答题选中信息吗？', {icon: 3}, function (index) {
                layer.close(index);
                var checkStatus = table.checkStatus('match'); //test即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.match_id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('todayall')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
        //批量关闭
        $('#closeAll').click(function () {
            layer.confirm('确认要批量关闭选中信息吗？', {icon: 3}, function (index) {
                layer.close(index);
                var checkStatus = table.checkStatus('match'); //test即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.match_id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('closeall')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })

        //批量显示答案
        $('#showAll').click(function () {
            layer.confirm('确认要批量显示答案选中信息吗？', {icon: 3}, function (index) {
                layer.close(index);
                var checkStatus = table.checkStatus('match'); //test即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.match_id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('showall')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
    });
</script>
</body>
</html>